home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / scav31.zip / SCAV30.ASM < prev    next >
Assembly Source File  |  1986-09-10  |  14KB  |  557 lines

  1. title scavenge Copyright (c) T. Jennings 1983
  2. ;downloaded from Simtel20's MSDOS.DISK-UTIL, 10 Sep 86
  3. ;
  4. ;****************************************
  5. ;*                    *
  6. ;*        SCAVENGE        *
  7. ;*                    *
  8. ;*    Mark bad blocks on MSDOS     *
  9. ;*    as allocated in the FAT.    *
  10. ;*                    *
  11. ;*    T. Jennings 5 June 82        *
  12. ;*      created 15 Sept. 82        *
  13. ;*    Modified 14 December 1984    *
  14. ;*        by David Gwillim        *
  15. ;*                    *
  16. ;*                    *
  17. ;****************************************
  18. ;
  19. ;***********************************************************************
  20. ;**                                                                   **
  21. ;**  SCAV2XX was modified by David Gwillim to dynamically allocate    **
  22. ;**  memory to the variables BLKBUF and FATBUF when the program       **
  23. ;**  is started - this drastically reduced the size of the .COM file  **
  24. ;**  from 17K on disk to just over 1K, while still allowing the       **
  25. ;**  checking of disks with block sizes up to 16K Bytes. Also         **
  26. ;**  changed was the access to disk to determine its statistics       **
  27. ;**  (Number of Blocks, Blocksize etc) this is now done AFTER the     **
  28. ;**  pause command when the program is first started, permitting      **
  29. ;**  the program to be run with a single floppy drive. Code was       **
  30. ;**  also added to display the block size of the disk in bytes        **
  31. ;**  as part of the statistics, plus some alert tones for various     **
  32. ;**  parts of the program.                                            **
  33. ;**                                                                   **
  34. ;**  I also added a more graceful exit than via ^C or Cntrl-Break     **
  35. ;**  as this would often leave you on the wrong drive if you aborted  **
  36. ;**  mid way through the block check and also would not give you the  **
  37. ;**  chance to update the FAT with any bad blocks found so far.       **
  38. ;**                                                                   **
  39. ;**  A logical improvement to the program would be to add to the      **
  40. ;**  code so the program could report the names of the files which    **
  41. ;**  contain any bad blocks found, so the user could handle those     **
  42. ;**  files, or at least be aware that the data in them was corrupted. **
  43. ;**                                                                   **
  44. ;**  This is a very useful program and can give you great peace of    **
  45. ;**  mind if you own a hard disk and want to be sure that all is OK.  **
  46. ;**  If anyone takes a crack at doing the improvements I mentioned    **
  47. ;**  or finds and fixes any bugs, I would be delighted to hear of     **
  48. ;**  them.                                                            **
  49. ;**                                                                   **
  50. ;**                     David Gwillim                                 **
  51. ;**                     1414 N. Catalina Street                       **
  52. ;**                     Los Angeles CA 90027                          **
  53. ;**                                                                   **
  54. ;************************************************************************
  55. ;
  56. ;Reads all sectors in logical MSDOS blocks
  57. ;and marks the file allocation tables such
  58. ;that the blocks are permanently allocated
  59. ;where CHKDSK will not deallocate them.
  60. ;
  61. ;
  62. ;This version works on any 2.xx MSDOS or
  63. ;PCDOS, on any media type, fixed or removable.
  64. ;One (major) limitation: it will not map out
  65. ;blocks that are already allocated to a file;
  66. ;it will say "block used", but won't tell you
  67. ;which file it is in.
  68. ;
  69. ;If SCAVENGE finds any bad blocks, it will ask
  70. ;you whether or not you want the disk updated.
  71. ;You can safely run it just to see if the disk 
  72. ;is OK.
  73. ;
  74. ;MASM, LINK, then EXE2BIN this to make a COM
  75. ;file. It will not run as an EXE file. NOTE:
  76. ;LINK will give you a 'Warning: no STACK 
  77. ;segment' error: ignore it.
  78. ;
  79. cr    equ    0dh
  80. lf    equ    0ah
  81.  
  82. ;Beep procedure count values
  83. ;---------------------------
  84. ;To generate a given freqency note out of the speaker with the Beep procedure
  85. ;on the PC using Channel 2 of the 8253 timer, the channel 2 count register
  86. ;must be loaded with a value such that the 8253 input clock frequency
  87. ;(1.19318 MHz) divided by the count figure equals the audio frequency.
  88.  
  89. f176Hz    equ    6779    ; 176 Hz count value
  90. f352Hz    equ    3390    ; 352 Hz count value
  91. f704Hz    equ    1695    ; 704 Hz count value
  92. f1408Hz    equ    847    ; 1408 Hz count value
  93.  
  94. page
  95. cgroup group code
  96. code segment byte public 'code'
  97. assume cs:cgroup,ds:cgroup,ss:cgroup
  98. ;
  99. ;MSDOS page 0 stuff.
  100. ;
  101.     org    5ch
  102. tfcb label byte
  103.  
  104.     org    80h
  105. tbuff label byte
  106.  
  107.     org    100h
  108. scavenge:
  109.     jmp    start
  110. ;
  111. ;Disk parameters:
  112. ;
  113. blkcnt    dw    (?)    ;blocks this disk
  114. blksize    dw    (?)    ;sectors per block
  115. secsize    dw    (?)    ;phys. sector size
  116. badcnt    dw    (?)    ;# bad blocks found
  117. newbad    dw    (?)    ;new bad ones
  118. block    dw    (?)    ;current block
  119. sector    dw    (?)    ;sector to read
  120. disk    db    (?)    ;selected disk
  121. curdsk    db    (?)    ;current disk.
  122. fatsec    dw    (?)    ;1st FAT sector,
  123. fatcnt    dw    (?)    ;FAT sec count.
  124.  
  125.     dw 128 dup (?)
  126. stack    dw    (?)    ;what else
  127. page
  128. ;
  129. ;Say who we are, describe the disk we are
  130. ;about to fix, ask to continue or abort.
  131. ;
  132. start:    mov    ax,cs
  133.     mov    ds,ax
  134.     cli            ;Disable interrupts while we move stack
  135.     mov    ss,ax
  136.     mov    sp,offset stack
  137.     sti            ;Re-enable interrupts
  138.     mov    dx,offset signon
  139.     call    putstr
  140.  
  141.     mov    bx,f176Hz    ;Alert user audibly
  142.     call    beep
  143.     mov    bx,f704Hz
  144.     call    beep
  145.     mov    bx,f352Hz
  146.     call    beep
  147.     mov    bx,f1408Hz
  148.     call    beep
  149.  
  150.     call    ina
  151.     or    al,20h        ;Make character lower case
  152.     cmp    al,'q'        ;Quit?
  153.     jne    st0
  154.     mov    dx,offset abort
  155.     call    putstr
  156.     int    20h
  157.  
  158. st0:    call    setup        ;get disk stuff
  159.     jnc    st1
  160.  
  161.     call    putstr
  162.     int    20h    ;error.
  163.  
  164. st1:    call    liststat    ;describe dsk
  165. ;
  166. ;Find all the bad blocks, if any, display them,
  167. ;ask if we should update the FAT. If so, write
  168. ;it out.
  169. ;
  170.     mov    dx,offset crlf
  171.     call    putstr
  172.     call    findbad        ;map bad,
  173.     call    listbad        ;list them,
  174.     cmp    newbad,0    ;if new bad
  175.     je    st2        ;blocks...
  176.  
  177.     mov    dx,offset updstr ;ask if we
  178.     call    putstr        ;should update
  179.     call    ina
  180.     and    al,5fh
  181.     cmp    al,'Y'
  182.     jne    st1A
  183.     mov    al,disk        ;write out the
  184.     mov    dx,fatsec    ;FAT,
  185.     mov    cx,fatcnt
  186.     mov    bx,offset fatbuf
  187.     int    26h
  188.     pop    ax        ;pop flags
  189.     mov    dx,offset update
  190.     call    putstr
  191.     jmp    st2
  192. st1A:    mov    dx,offset noupdte
  193.     call    putstr
  194. st2:    mov    al,curdsk    ;reselect the
  195.     call    seldsk        ;original disk
  196.     int    20h
  197.  
  198. signon    db    cr,lf,9,'*********************************************'
  199.     db    cr,lf,9,'* DOS 2.xx Bad Sector Mapper - Version 3.00 *'
  200.     db    cr,lf,9,'* Updated by David Gwillim 18 December 1984 *'
  201.     db    cr,lf,9,'* Original program by T. Jennings 5 June 83 *'
  202.     db    cr,lf,9,'*********************************************'
  203.     db    cr,lf,lf
  204.     db    'Type Q to abort at any time, any other key to continue ...'
  205.     db    cr,lf,'$'
  206. updstr    db    cr,lf,lf,'Want the disk updated? [y,n] $'
  207. noupdte    db    cr,lf,lf,'FAT not updated',cr,lf,'$'
  208. update    db    cr,lf,lf,'FAT updated',cr,lf,'$'
  209. crlf    db    cr,lf,'$'
  210. page
  211. ;
  212. ;Get the data on the specified disk. Return 
  213. ;carry if no drive specified. Returns ES:DI
  214. ;pointing to the FAT for the selected drive.
  215. ;
  216. setup:    call    initdsk        ;reset dsk sys,
  217.     call    getdsk        ;get current,
  218.     mov    curdsk,al    ;save it,
  219.     mov    al,tfcb        ;make sure a
  220.     cmp    al,0        ;new one spec'd
  221.     stc            ;quit if none,
  222.     mov    dx,offset strstr
  223.     jz    gd1
  224.     dec    al        ;make 0-N,
  225.     mov    disk,al
  226.     call    seldsk        ;select,
  227.  
  228.     push    ds        ;save local DS,
  229.     mov    ah,1bh
  230.     int    21h
  231.     pop    ds
  232.     mov    blkcnt,dx    ;save # blocks,
  233.     mov    secsize,cx    ;sector size,
  234. ;th    mov    ah,0
  235.     xor    ah,ah    ;th
  236.     mov    blksize,ax    ;secs/block.
  237.  
  238.     push    ds        ;now get the
  239.     mov    dl,disk
  240.     inc    dl        ;drive 1=A, b=2
  241.     mov    ah,32h        ;FAT,
  242.     int    21h        ;get the DPB,
  243.  
  244.     mov    cx,[bx+15]    ;CX= sec count,
  245. ;th    mov    ch,0
  246.     xor    ch,ch    ;th
  247.     mov    dx,[bx+6]    ;DX= 1st sec,
  248.     pop    ds
  249.     mov    fatcnt,cx    ;save both,
  250.     mov    fatsec,dx
  251.  
  252.     mov    al,disk        ;AL= drive #,
  253.     mov    bx,offset fatbuf ;DS:BX= buffer
  254.     int    25h        ;read the FAT,
  255.     pop    ax        ;pop flags
  256.     mov    dx,offset bscstr
  257. gd1:    ret
  258. strstr    db    cr,lf,'Must specify a disk drive.$'
  259. bscstr    db    cr,lf,'Bad FAT sector: disk not useable.$'
  260.  
  261. page
  262. ;
  263. ;Read the entire disk looking for bad blocks.
  264. ;When one is found, go mark it as an allocated
  265. ;bad block.
  266. ;
  267. findbad:
  268.     mov    block,0        ;1st block,
  269.     mo